﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKSparseDistance;
using YJKSparseDistance.ControlLayer;
using YJKSparseDistance.ModelLayer;
using YJKInspectModelFunc.ControlLayer;
using YJKInspectModelFunc.ModelLayer;

namespace YJKSparseDisOfRoom.ControlLayer
{
	internal class EvacutionDistanceLinker
	{
		public List<AreaPacker_EvacuationDistance> LstAllAreaPacker
		{
			get
			{
				return this.m_lstAllAreaPacker;
			}
			private set
			{
				this.m_lstAllAreaPacker = value;
			}
		}

		public int AreaCount
		{
			get
			{
				return this.m_nAreaCount;
			}
			private set
			{
				this.m_nAreaCount = value;
			}
		}

		internal List<RoomPacker_EvacuationDistance> FindAllRunWayRoom(Autodesk.Revit.DB.Document inputDoc, List<Level> inputSelectLevels)
		{
			List<RoomPacker_EvacuationDistance> list = new List<RoomPacker_EvacuationDistance>();
			List<RoomPacker_EvacuationDistance> allRunWayRoomWithArea = this.GetAllRunWayRoomWithArea(TempleCmd.UseUiDocument, inputSelectLevels, out this.m_lstAllAreaPacker);
			this.AreaCount = this.m_lstAllAreaPacker.Count;
			foreach (RoomPacker_EvacuationDistance roomPacker_EvacuationDistance in allRunWayRoomWithArea)
			{
				if (roomPacker_EvacuationDistance.ParentAreaPacker != null)
				{
					list.Add(roomPacker_EvacuationDistance);
				}
			}
			return list;
		}

		private List<RoomPacker_EvacuationDistance> GetAllRunWayRoomWithArea(UIDocument inputUiDoc, List<Level> inputSelectLevel, out List<AreaPacker_EvacuationDistance> lstAllAreaPackers)
		{
			Document document = inputUiDoc.Document;
			List<ICloseCurveAnalays> frontRoomData = EvacuationDistanceArch.GetFrontRoomData(inputUiDoc, inputSelectLevel);
			List<Phase> list = new List<Phase>();
			foreach (object obj in document.Phases)
			{
				Phase item = (Phase)obj;
				list.Add(item);
			}
			List<AreaPacker_EvacuationDistance> areas = new AreaGeter().GetAreas(document, inputSelectLevel, frontRoomData, list);
			lstAllAreaPackers = areas;
			this.AreaCount = this.m_lstAllAreaPacker.Count;
			List<BaseRoomPacker> list2 = new List<BaseRoomPacker>();
			foreach (KeyValuePair<int, BaseElementPacker> keyValuePair in ElementPackerManger.DicNowValues)
			{
				if (keyValuePair.Value is BaseRoomPacker)
				{
					list2.Add(keyValuePair.Value as BaseRoomPacker);
				}
			}
            return YJKSparseDistance.Utility.FindAllRunWayRooms(list2, frontRoomData, true);
		}

		private List<AreaPacker_EvacuationDistance> m_lstAllAreaPacker;

		private int m_nAreaCount;
	}
}
